package edu.pmfbl.mnr.sem.mcmatp.gui;

import javax.swing.*;
import com.borland.jbcl.layout.VerticalFlowLayout;
import java.awt.*;
import com.borland.jbcl.layout.*;

import edu.pmfbl.mnr.sem.mcmatp.app.*;

/**
 * <p>Title: MCMA Test Preview</p>
 *
 * <p>Description: </p>
 *
 * <p>Copyright: Copyright (c) 2009</p>
 *
 * <p>Company: KrndijaSoft</p>
 *
 * @author Ninoslav Krndija
 * @version 1.0
 */
public class PitanjePanel extends JPanel
{
  AppDataModule appDataModule = AppDataModule.getDataModule();
  Test test = Test.getInstance();
  long id;
  int tacnih;
  float osvojeniBodovi;

  public PitanjePanel() {
    try {
      jbInit();
    }
    catch (Exception ex) {
      ex.printStackTrace();
    }
  }

  private void jbInit() throws Exception
  {
    VerticalFlowLayout verticalFlowLayout1 = new VerticalFlowLayout();

    this.setLayout(borderLayout1);
    rednibrLabel.setFont(new java.awt.Font("Dialog", Font.BOLD, 12));
    rednibrLabel.setHorizontalAlignment(SwingConstants.CENTER);
    rednibrLabel.setHorizontalTextPosition(SwingConstants.RIGHT);
    id = appDataModule.getPitanjaDataSet().getLong("id");
    infoPanel.setLayout(verticalFlowLayout1);
    verticalFlowLayout1.setVgap(2);
    bodoviLabel.setHorizontalAlignment(SwingConstants.CENTER);
    bodoviLabel.setHorizontalTextPosition(SwingConstants.RIGHT);
    bodoviLabel.setText(Long.toString(appDataModule.getPitanjaDataSet().getLong("bodovi")));
    sadrzajPanel.setLayout(verticalFlowLayout2);
    tekstpitanjaLabel.setFont(new java.awt.Font("Dialog", Font.BOLD, 11));
    tekstpitanjaLabel.setToolTipText("");
    tekstpitanjaLabel.setText(appDataModule.getPitanjaDataSet().getString("tekstpitanja"));
    verticalFlowLayout2.setVgap(2);
    sadrzajPanel.add(tekstpitanjaLabel);

    /**
     * Formira sadrzajPanel dodavanjem odgovorPanel-a za svaki odgovor.
     * Prolazi kroz odgovorDataSet i za svaki odgovor formira OdgovorPanel i
     * dodaje formirani panel na sadrzajPanel.
     */
    appDataModule.getOdgovoriDataSet().first();
    while(appDataModule.getOdgovoriDataSet().inBounds())
    {
      if(appDataModule.getOdgovoriDataSet().getBoolean("tacan"))
        tacnih++;
      OdgovorPanel odgovorPanel = new OdgovorPanel();
      sadrzajPanel.add(odgovorPanel);

      appDataModule.getOdgovoriDataSet().next();
    }

    infoTacnostLabel.setVisible(false);
    rezultatLabel.setVisible(false);
    infoLabel.setVisible(false);
    infoLabel.setText(appDataModule.getPitanjaDataSet().getString("info"));
    sadrzajPanel.add(infoTacnostLabel);
    sadrzajPanel.add(rezultatLabel);
    sadrzajPanel.add(infoLabel);

    this.add(infoPanel, java.awt.BorderLayout.WEST);
    infoPanel.add(rednibrLabel);
    infoPanel.add(bodoviLabel);
    this.add(sadrzajPanel, java.awt.BorderLayout.CENTER);

  }

  public long getId()
  {
    return id;
  }

  public void setRednibrLabel(long rb)
  {
    rednibrLabel.setText(Long.toString(rb));
  }

  public JPanel getSadrzajPanel()
  {
    return sadrzajPanel;
  }

  public void povecajOsvojeniBodovi(float inc)
  {
    osvojeniBodovi = osvojeniBodovi + inc;
  }

  public float getOsvojeniBodovi()
  {
    return osvojeniBodovi;
  }

  public void setOsvojeniBodovi(float value)
  {
    osvojeniBodovi = value;
  }

  public int getTacnih()
  {
    return tacnih;
  }

  public JLabel getInfoTacnostLabel()
  {
    return infoTacnostLabel;
  }

  public JLabel getRezultatLabel()
  {
    return rezultatLabel;
  }

  public void setComponentsVisible(boolean visible)
  {
    infoTacnostLabel.setVisible(visible);
    rezultatLabel.setVisible(visible);
    infoLabel.setVisible(visible);
  }

  BorderLayout borderLayout1 = new BorderLayout();
  VerticalFlowLayout verticalFlowLayout1 = new VerticalFlowLayout();
  VerticalFlowLayout verticalFlowLayout2 = new VerticalFlowLayout();
  JPanel infoPanel = new JPanel();
  JPanel sadrzajPanel = new JPanel();
  JLabel rednibrLabel = new JLabel();
  JLabel bodoviLabel = new JLabel();
  JLabel tekstpitanjaLabel = new JLabel();
  JLabel infoTacnostLabel = new JLabel();
  JLabel rezultatLabel = new JLabel();
  JLabel infoLabel = new JLabel();

}
